//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "BondResults.h"
using namespace Cephei::QL::Instruments;
#include <gen/QL/InstrumentResults.h>
using namespace Cephei::QL;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Instruments::CBondResults::CBondResults (boost::shared_ptr<QuantLib::BondResults>& childNative, Object^ owner) : CInstrumentResults(CBondResults::typeid)
{
#ifdef HANDLE
	_phBondResults = NULL;
#endif
	_ppBondResults = &childNative;
    _ppInstrumentResults = new boost::shared_ptr<QuantLib::InstrumentResults> (boost::dynamic_pointer_cast<QuantLib::InstrumentResults> (*_ppBondResults));
}
Cephei::QL::Instruments::CBondResults::CBondResults (QuantLib::BondResults& childNative, Object^ owner) : CInstrumentResults(CBondResults::typeid)
{
#ifdef HANDLE
	_phBondResults = NULL;
#endif
	_ppBondResults = new boost::shared_ptr<QuantLib::BondResults> (&childNative);
    _ppInstrumentResults = new boost::shared_ptr<QuantLib::InstrumentResults> (boost::dynamic_pointer_cast<QuantLib::InstrumentResults> (*_ppBondResults));
    _BondResultsOwner = owner;
    _InstrumentResultsOwner = owner;
}

Cephei::QL::Instruments::CBondResults::CBondResults (CBondResults^ copy) : CInstrumentResults(CBondResults::typeid)
{
#ifdef HANDLE
	_phBondResults = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppBondResults = new boost::shared_ptr<QuantLib::BondResults> (copy->GetShared());
        _ppInstrumentResults = new boost::shared_ptr<QuantLib::InstrumentResults> (boost::dynamic_pointer_cast<QuantLib::InstrumentResults> (*_ppBondResults));
    }
}
Cephei::QL::Instruments::CBondResults::CBondResults (System::Type^ t) : CInstrumentResults(CBondResults::typeid)
{
#ifdef HANDLE
	_phBondResults = NULL;
#endif
	if (!t->IsSubclassOf(CBondResults::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::CBondResults::CBondResults (QuantLib::Handle<QuantLib::BondResults>& childNative, Object^ owner)  : CInstrumentResults(CBondResults::typeid)
{
	_phBondResults = &childNative;
	_ppBondResults = &static_cast<boost::shared_ptr<QuantLib::BondResults>>(childNative.currentLink());
    _ppInstrumentResults = new boost::shared_ptr<QuantLib::InstrumentResults> (boost::dynamic_pointer_cast<QuantLib::InstrumentResults> (*_ppBondResults));
    _BondResultsOwner = owner;
}
Cephei::QL::Instruments::CBondResults::CBondResults (QuantLib::Handle<QuantLib::BondResults> childNative)  : CInstrumentResults(CBondResults::typeid)
{
	_phBondResults = &childNative;
	_ppBondResults = &static_cast<boost::shared_ptr<QuantLib::BondResults>>(childNative.currentLink());
    _ppInstrumentResults = new boost::shared_ptr<QuantLib::InstrumentResults> (boost::dynamic_pointer_cast<QuantLib::InstrumentResults> (*_ppBondResults));
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::CBondResults::CBondResults (QuantLib::BondResults childNative)  : CInstrumentResults(CBondResults::typeid)
{
#ifdef HANDLE
	_phBondResults = NULL;
#endif
	_ppBondResults = new boost::shared_ptr<QuantLib::BondResults> (new QuantLib::BondResults (childNative));
    _ppInstrumentResults = new boost::shared_ptr<QuantLib::InstrumentResults> (boost::dynamic_pointer_cast<QuantLib::InstrumentResults> (*_ppBondResults));
}
#endif

Cephei::QL::Instruments::CBondResults::~CBondResults ()
{
    if (_ppBondResults != NULL)
    {
	    delete _ppBondResults;
        _ppBondResults = NULL;
    }
}
Cephei::QL::Instruments::CBondResults::!CBondResults ()
{
    if (_ppBondResults != NULL)
    {
	    delete _ppBondResults;
    }
}
QuantLib::BondResults& Cephei::QL::Instruments::CBondResults::GetReference ()
{
    if (_ppBondResults == NULL) throw gcnew NativeNullException ();
	return **_ppBondResults;
}
boost::shared_ptr<QuantLib::BondResults>& Cephei::QL::Instruments::CBondResults::GetShared ()
{
    if (_ppBondResults == NULL) throw gcnew NativeNullException ();
	return *_ppBondResults;
}
QuantLib::BondResults* Cephei::QL::Instruments::CBondResults::GetPointer ()
{
    if (_ppBondResults == NULL) throw gcnew NativeNullException ();
	return &**_ppBondResults;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::BondResults>& Cephei::QL::Instruments::CBondResults::GetHandle ()
{
	if (_phBondResults == NULL)
	{
		_phBondResults = new Handle<QuantLib::BondResults> (*_ppBondResults);
	}
	return *_phBondResults;
}
#endif
bool Cephei::QL::Instruments::CBondResults::HasNative () 
{
	return (_ppBondResults != NULL);
}

Cephei::QL::Instruments::IBondResults^ Cephei::QL::Instruments::CBondResults::Reset::get ()
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
    	(*_ppBondResults)->reset ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

